import { createStore } from "vuex";
import moment from 'moment'

const store= createStore({
  state: {
    message: "",
    username: localStorage.getItem('username') ? localStorage.getItem('username'):'',
    sex: localStorage.getItem('sex') ? localStorage.getItem('sex'):'男',
    initialTime: localStorage.getItem('initialTime') ? localStorage.getItem('initialTime'):'',
    signFormTimeLong: localStorage.getItem('signFormTimeLong') ? localStorage.getItem('signFormTimeLong'):'',
    signFormTime: localStorage.getItem('signFormTime') ? localStorage.getItem('signFormTime'):'',
    replyTime: localStorage.getItem('replyTime') ? localStorage.getItem('replyTime'):'',
    leaveTime: localStorage.getItem('leaveTime') ? localStorage.getItem('leaveTime'):'',
    backTime: localStorage.getItem('backTime') ? localStorage.getItem('backTime'):'',
    xuehao: localStorage.getItem('xuehao') ? localStorage.getItem('xuehao'): "2021120"+Math.ceil(Math.random()*6).toString()+Math.ceil(Math.random()*7).toString()+Math.ceil(Math.random()*8).toString(),
    domitory: (4+Math.ceil(Math.random()*4))+'舍'+Math.ceil(Math.random()*6)+Math.ceil(Math.random()*47).toString().padStart(2, '0'),
    phone: '1800535'+(1111+Math.ceil(Math.random()*8888)).toString(),
    reasonList: ["牙疼，定期复诊", "补办身份证", "教研室团建活动", "出校买药", "慢性阑尾炎去准备治疗"],
    reason: localStorage.getItem('reason') ? localStorage.getItem('reason'):'',
  },
  mutations: {
    setName(state, username) {
      state.username = username;
      localStorage.setItem('username', username)
    },
    setSex(state, sex) {
      state.sex = sex;
      localStorage.setItem('sex', sex)
    },
    setInitialTime(state, initialTime) {
      state.initialTime = initialTime;
      localStorage.setItem('initialTime', initialTime)
      state.signFormTimeLong = moment(Date()).add(-2, 'days').format("YYYY-MM-DD")+" 1"+Math.floor(Math.random()*10)+":"+Math.floor(Math.random()*60).toString().padStart(2, '0');
      localStorage.setItem('signFormTimeLong', state.signFormTimeLong)
      state.signFormTime = moment(Date()).add(-2, 'days').format("YYYY-MM-DD");
      localStorage.setItem('signFormTime', state.signFormTime)
      state.replyTime = moment(Date()).add(-1, 'days').format("YYYY-MM-DD");
      localStorage.setItem('replyTime', state.replyTime)
      state.leaveTime = moment(Date()).format("YYYY-MM-DD")+" 9:00:00";
      localStorage.setItem('leaveTime', state.leaveTime)
      state.backTime = moment(Date()).format("YYYY-MM-DD")+" 21:30:00";
      localStorage.setItem('backTime', state.backTime)
    },
    setXuehao(state, xuehao){
      state.xuehao = xuehao;
      localStorage.setItem('xuehao', xuehao)
    },
    setReason(state, reason){
      state.reason = reason;
      localStorage.setItem('reason', reason)
    },
    setMessage(state, message){
      state.message = message;
    },
  },
  actions: {},
  getters: {
  },
});

export default store;